package com.taxigang.client.uibinder;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.micro.TaxiGangCreator;

public class AlertOkCancel extends Composite {

	private static AlertOkCancelUiBinder uiBinder = GWT
	.create(AlertOkCancelUiBinder.class);

	interface AlertOkCancelUiBinder extends UiBinder<Widget, AlertOkCancel> {
	}


	private PopupPanel popupPanel = new DecoratedPopupPanel(false,true);

	@UiField
	Button okButton;
	@UiField
	Button cancelButton;
	@UiField
	Label alertText1;
	@UiField
	Label alertText2;
	@UiField
	Label alertText3;
	@UiField
	Label alertText4;
	
	public AlertOkCancel(final Command cmd,String title, String text, boolean showCancel,String width) {
		init(cmd,title, showCancel, width);
		alertText1.setText(text);

	}

	public AlertOkCancel(final Command cmd,String title, String[] text, boolean showCancel,String width) {
		init(cmd,title, showCancel, width);
		if (text.length >0){
			alertText1.setText(text[0]);
		}
		if (text.length >1){
			alertText2.setText(text[1]);
		}
		if (text.length >2){
			alertText3.setText(text[2]);
		}
		if (text.length >3){
			alertText4.setText(text[3]);
		}
	}


	public void init(final Command cmd,String title, boolean showCancel,String width) {
		initWidget(uiBinder.createAndBindUi(this));
		okButton.setText("OK");
		cancelButton.setText(TaxiGangCreator.taxiGangConstants.cancel());

		popupPanel.setTitle("<p><b>"+title+"</b></p>");
		popupPanel.setWidth(width);
		//popupPanel.setWidth("422px");
		popupPanel.setGlassEnabled(true);
//		popupPanel.setHTML("<p><b>"+title+"</b></p>");

		popupPanel.setWidget(this);

		okButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				if (cmd != null){
					cmd.execute();
				}
				popupPanel.hide();
			}
		});
		cancelButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				popupPanel.hide();

			}
		});
		cancelButton.setVisible(showCancel);

	}


	public void show(){
		popupPanel.center();

		popupPanel.show();
	}

}
